package com.teyao.teyao_back.controller;

import com.teyao.teyao_back.entity.OrderDetails;

import com.teyao.teyao_back.entity.ResponseMessage;
import com.teyao.teyao_back.service.OrderDetailsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


@RestController
@CrossOrigin
@RequestMapping("/OrderDetails")
public class OrderDetailsController {
    @Autowired
    private OrderDetailsService orderDetailsService;

    @PostMapping("/updateFinish")
    public ResponseMessage updateFinishQuantity(String orderId, Integer productId, Integer finishQuantity) {
        OrderDetails orderDetails = new OrderDetails();
        orderDetails.setOrderId(orderId);
        orderDetails.setProductId(productId);
        orderDetails.setFinishQuantity(finishQuantity);
        return orderDetailsService.updateFinishQuantity(orderDetails);
    }

    @PostMapping("/insert")
    public ResponseMessage insert(List<OrderDetails> orderDetailsList) {
        ResponseMessage responseMessage = new ResponseMessage();
        responseMessage.setSuccess(orderDetailsService.saveBatch(orderDetailsList));
        return responseMessage;
    }


    @PostMapping("/test")
    public ResponseMessage test(@RequestBody ArrayList<OrderDetails> orderDetailsArrayList) {
        for (OrderDetails o : orderDetailsArrayList) {
            System.out.println(o);
        }
        ResponseMessage responseMessage = new ResponseMessage();
        responseMessage.setSuccess(orderDetailsService.saveBatch(orderDetailsArrayList));
        return responseMessage;
    }
}
